package com.ncloud.crm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.ncloud.crm.entity.order.OrderAttr;

/**
 * Created by shiqiang on 2017/4/11.
 */
@Mapper
public interface OrderAttrMapper {
    @Select(value = { "select * from bs_o_attr where id = #{id} and attr_type = #{attrType}" })
    @Results({ @Result(column = "id", property = "id"), @Result(column = "modify_tag", property = "modifyTag"),
            @Result(column = "attr_type", property = "attrType"),@Result(column = "attr_code", property = "attrCode"),
            @Result(column="attr_value",property="attrValue"),@Result(column="begin_date",property="beginDate"),
            @Result(column="end_date",property="endDate"),@Result(column="attr_id",property="attrId")})
    public List<OrderAttr> getAttrById(@Param("id")Long orderId,@Param("attrType")String attrType);
    
    @Select(value = { "select * from bs_o_attr where id = #{id} and attr_type = #{attrType} and attr_code=#{key}" })
    @Results({ @Result(column = "id", property = "id"), @Result(column = "modify_tag", property = "modifyTag"),
            @Result(column = "attr_type", property = "attrType"),@Result(column = "attr_code", property = "attrCode"),
            @Result(column="attr_value",property="attrValue"),@Result(column="begin_date",property="beginDate"),
            @Result(column="end_date",property="endDate"),@Result(column="attr_id",property="attrId")})
    public OrderAttr getAttrByKey(@Param("id")Long orderId,@Param("attrType")String attrType,@Param("key")String key);
    
    @Insert(value = "insert into bs_o_attr(id,modify_tag,attr_type,attr_code,attr_value,begin_date,end_date,attr_id) " +
            "values(#{id},#{modifyTag},#{attrType},#{attrCode},#{attrValue},#{beginDate},#{endDate},#{attrId})")
    public int insertOrderAttr(OrderAttr orderAttr);
}
